package net.lab1024.sa.admin.module.business.exam.controller;

import cn.idev.excel.FastExcel;
import com.alibaba.fastjson.JSON;
import net.lab1024.sa.admin.module.business.exam.dao.QuestionsDao;
import net.lab1024.sa.admin.module.business.exam.domain.entity.QuestionsEntity;
import net.lab1024.sa.admin.module.business.exam.domain.form.add.QuestionsAddForm;
import net.lab1024.sa.admin.module.business.exam.domain.form.query.QuestionsQueryForm;
import net.lab1024.sa.admin.module.business.exam.domain.form.update.QuestionsUpdateForm;
import net.lab1024.sa.admin.module.business.exam.domain.vo.QuestionsVO;
import net.lab1024.sa.admin.module.business.exam.service.QuestionsService;
import net.lab1024.sa.admin.module.business.goods.domain.form.GoodsImportForm;
import net.lab1024.sa.base.common.domain.ValidateList;
import net.lab1024.sa.base.common.exception.BusinessException;
import net.lab1024.sa.base.common.util.SmartBeanUtil;
import net.lab1024.sa.base.common.util.SmartExcelUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;

/**
 * 课程分类 Controller
 *
 * @Author AKITA
 * @Date 2025-06-06 11:08:34
 * @Copyright AKITA
 */

@RestController
@Tag(name = "课程分类")
public class QuestionsController {

    @Resource
    private QuestionsService questionsService;

    @Resource
    private QuestionsDao questionsDao;

    @PostMapping("/questions/queryPage")
    public ResponseDTO<PageResult<QuestionsVO>> queryPage(@RequestBody @Valid QuestionsQueryForm queryForm) {
        return ResponseDTO.ok(questionsService.queryPage(queryForm));
    }
    @PostMapping("/questions/add")
    public ResponseDTO<Long> add(@RequestBody @Valid QuestionsAddForm addForm) {
        return questionsService.add(addForm);
    }

    @PostMapping("/questions/update")
    public ResponseDTO<String> update(@RequestBody @Valid QuestionsUpdateForm updateForm) {
        return questionsService.update(updateForm);
    }

    @PostMapping("/questions/batchDelete")
    public ResponseDTO<String> batchDelete(@RequestBody ValidateList<Long> idList) {
        return questionsService.batchDelete(idList);
    }

    @GetMapping("/questions/delete/{docEntry}")
    public ResponseDTO<String> batchDelete(@PathVariable Long docEntry) {
        return questionsService.delete(docEntry);
    }

    @GetMapping("/questions/info/{docEntry}")
    public ResponseDTO<QuestionsEntity> info(@PathVariable Long docEntry) {
        return questionsService.info(docEntry);
    }
    @RequestMapping("/questions/export")
    public void export(@RequestBody QuestionsQueryForm queryForm,HttpServletResponse response) throws IOException {
        List<QuestionsEntity> questionsEntities = questionsDao.selectList(null);
        SmartExcelUtil.exportExcel(response, "试题.xlsx", "试题", QuestionsEntity.class, questionsEntities);
    }

    @RequestMapping("/questions/import")
    public ResponseDTO<String> imPort(@RequestParam MultipartFile file)   {
        return questionsService.imPort(file);
    }

}
